package com.householditemtwo.index.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.householditemtwo.common.entity.Compary;
import com.householditemtwo.common.entity.Product;
import com.householditemtwo.common.entity.Producttype;
import com.householditemtwo.common.entity.Produtimg;
import com.householditemtwo.common.utils.BaseServlet;
import com.householditemtwo.index.dao.AboutDao;
import com.householditemtwo.index.dao.ProductDao;

/**
 * Servlet implementation class AboutServlet
 */
@WebServlet("/ProductServlet")
public class ProductServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
	
	
	
	//创建DAo
	ProductDao dao=new ProductDao();
			/**
			 * 
			 * @param request
			 * @param response
			 * @throws ServletException
			 * @throws IOException
			 */
			
	public void toProductlist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String pteid=request.getParameter("pteid");
		
		//调用dao查询数据
		
		
		//查询产品分类信息
		List<Producttype> protypeList=dao.selectAllProducttype();
		
		//查询某个产品分类的所有产品
		List<Product> proList=dao.selectAllProductByType(Integer.parseInt(pteid));
		
		//把产品分类信息保存到request里面
		request.setAttribute("protypeList", protypeList);
		request.setAttribute("proList", proList);
		request.setAttribute("pteid", pteid);
		
		
		//转发到productlist.jsp页面
		request.getRequestDispatcher("productlist.jsp").forward(request, response);
	}
	
/**
 * 跳转到产品详情页
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 */

	
public void toProductDetails(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	String proid=request.getParameter("proid");
		
		//调用dao查询数据
		
		
		
		Product product=dao.selectProductById(Integer.parseInt(proid));
		//查询产品分类信息
		List<Producttype> protypeList=dao.selectAllProducttype();
		//根据产品id查询产品的小图片
		List<Produtimg> ProimgList=dao.selectProdutimgByProid(Integer.parseInt(proid));
		
		request.setAttribute("ProimgList", ProimgList);
		request.setAttribute("product", product);
		request.setAttribute("protypeList", protypeList);
		
		//转发到productlist.jsp页面
		request.getRequestDispatcher("productdetails.jsp").forward(request, response);
	}
}
